<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户注册</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Arial', sans-serif;
        }
        
        body {
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        
        .register-container {
            background-color: white;
            padding: 40px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
        }
        
        .register-header {
            text-align: center;
            margin-bottom: 30px;
        }
        
        .register-header h1 {
            color: #333;
            font-size: 24px;
            margin-bottom: 10px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: 500;
        }
        
        .form-group input {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        
        .form-group input:focus {
            border-color: #4285f4;
            outline: none;
        }
        
        .password-strength {
            margin-top: 5px;
            font-size: 12px;
            color: #666;
        }
        
        .strength-bar {
            height: 4px;
            background-color: #eee;
            margin-top: 5px;
            border-radius: 2px;
            overflow: hidden;
        }
        
        .strength-level {
            height: 100%;
            width: 0;
            background-color: #e0e0e0;
            transition: width 0.3s, background-color 0.3s;
        }
        
        .register-button {
            width: 100%;
            padding: 12px;
            background-color: #34a853;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.3s;
            margin-top: 10px;
        }
        
        .register-button:hover {
            background-color: #2d9248;
        }
        
        .login-link {
            text-align: center;
            margin-top: 20px;
            font-size: 14px;
        }
        
        .login-link a {
            color: #4285f4;
            text-decoration: none;
        }
        
        .error-message {
            color: #d32f2f;
            font-size: 14px;
            margin-top: 5px;
            display: none;
        }
        
        .terms {
            font-size: 12px;
            color: #666;
            margin-top: 15px;
        }
        
        .terms input {
            margin-right: 5px;
        }
    </style>
</head>
<body>
    <div class="register-container">
        <div class="register-header">
            <h1>创建新账户</h1>
            <p>填写以下信息完成注册</p>
        </div>
        
        <form id="registerForm">
            <div class="form-group">
                <label for="username">用户名</label>
                <input type="text" id="username" name="username" placeholder="请输入用户名" required>
                <div id="usernameError" class="error-message">用户名不能为空</div>
            </div>
            
            <div class="form-group">
                <label for="email">电子邮箱</label>
                <input type="email" id="email" name="email" placeholder="请输入电子邮箱" required>
                <div id="emailError" class="error-message">请输入有效的电子邮箱</div>
            </div>
            
            <div class="form-group">
                <label for="password">密码</label>
                <input type="password" id="password" name="password" placeholder="请输入密码" required>
                <div class="password-strength">
                    <div class="strength-bar">
                        <div class="strength-level" id="strengthLevel"></div>
                    </div>
                    <span id="strengthText">密码强度: 弱</span>
                </div>
                <div id="passwordError" class="error-message">密码不能少于8个字符</div>
            </div>
            
            <div class="form-group">
                <label for="confirmPassword">确认密码</label>
                <input type="password" id="confirmPassword" name="confirmPassword" placeholder="请再次输入密码" required>
                <div id="confirmPasswordError" class="error-message">两次输入的密码不一致</div>
            </div>
            
            <div class="terms">
                <input type="checkbox" id="agreeTerms" name="agreeTerms" required>
                <label for="agreeTerms">我已阅读并同意<a href="#">服务条款</a>和<a href="#">隐私政策</a></label>
                <div id="termsError" class="error-message">必须同意条款才能注册</div>
            </div>
            
            <button type="submit" class="register-button">注册</button>
        </form>
        
        <div class="login-link">
            <span>已有账号? </span>
            <a href="login.html">立即登录</a>
        </div>
    </div>

    <script>
        // 密码强度检测
        document.getElementById('password').addEventListener('input', function() {
            const password = this.value;
            const strengthLevel = document.getElementById('strengthLevel');
            const strengthText = document.getElementById('strengthText');
            
            // 重置
            strengthLevel.style.width = '0%';
            strengthLevel.style.backgroundColor = '#e0e0e0';
            strengthText.textContent = '密码强度: 弱';
            
            if (password.length === 0) return;
            
            // 简单密码强度检测
            let strength = 0;
            
            // 长度检测
            if (password.length >= 8) strength += 1;
            if (password.length >= 12) strength += 1;
            
            // 复杂度检测
            if (/[A-Z]/.test(password)) strength += 1; // 包含大写字母
            if (/[0-9]/.test(password)) strength += 1; // 包含数字
            if (/[^A-Za-z0-9]/.test(password)) strength += 1; // 包含特殊字符
            
            // 更新UI
            if (strength <= 2) {
                strengthLevel.style.width = '33%';
                strengthLevel.style.backgroundColor = '#ff5252';
                strengthText.textContent = '密码强度: 弱';
            } else if (strength <= 4) {
                strengthLevel.style.width = '66%';
                strengthLevel.style.backgroundColor = '#ffb74d';
                strengthText.textContent = '密码强度: 中';
            } else {
                strengthLevel.style.width = '100%';
                strengthLevel.style.backgroundColor = '#4caf50';
                strengthText.textContent = '密码强度: 强';
            }
        });
        
        // 表单提交处理
        document.getElementById('registerForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            // 获取输入值
            const username = document.getElementById('username').value.trim();
            const email = document.getElementById('email').value.trim();
            const password = document.getElementById('password').value.trim();
            const confirmPassword = document.getElementById('confirmPassword').value.trim();
            const agreeTerms = document.getElementById('agreeTerms').checked;
            
            // 重置错误信息
            document.getElementById('usernameError').style.display = 'none';
            document.getElementById('emailError').style.display = 'none';
            document.getElementById('passwordError').style.display = 'none';
            document.getElementById('confirmPasswordError').style.display = 'none';
            document.getElementById('termsError').style.display = 'none';
            
            // 验证
            let isValid = true;
            
            if (!username) {
                document.getElementById('usernameError').style.display = 'block';
                isValid = false;
            }
            
            if (!email || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
                document.getElementById('emailError').style.display = 'block';
                isValid = false;
            }
            
            if (password.length < 8) {
                document.getElementById('passwordError').style.display = 'block';
                isValid = false;
            }
            
            if (password !== confirmPassword) {
                document.getElementById('confirmPasswordError').style.display = 'block';
                isValid = false;
            }
            
            if (!agreeTerms) {
                document.getElementById('termsError').style.display = 'block';
                isValid = false;
            }
            
            if (isValid) {
                // 这里可以添加AJAX请求到服务器处理注册
                console.log('注册信息:', { username, email, password });
                
                // 模拟注册成功
                alert('注册成功! 请登录您的账户。');
                // window.location.href = 'login.html'; // 跳转到登录页
            }
        });
    </script>
</body>
</html>
